<template>
	<view class="warpper">
		<scroll-view class="pay_container" scroll-y="true" :enhanced="true" :show-scrollbar="true"
			@scrolltolower="loadMore()">
			<view class="tab_container">
				<view v-for="(item,index) in tabList" :key="index" class="tab_item">
					<view :class="item.value==state?'f-color-active':'f-color'" @click="tabClick(item)">
						{{item.label}}
					</view>
				</view>
			</view>
			<view v-if="payList.length > 0">
				<view class="pay_item" v-for="(item,index) in payList" :key="index">
					<view class="pay_content">
						<view class="label">
							<span>下订单</span>
							({{item.name}})
						</view>
						<view :style="{color:state == 0 ? 'orange' : (state == 1 ? 'green' : 'red')}"
							style="display: flex;">
							{{stateText(state)}}
							<view v-if="state == 2" style="color: #6739b6;" @click="viewReason(item.remark)">
								(查看原因)
							</view>
						</view>
						<view class="price">￥{{item.total}}</view>
					</view>
					<view class="pay_time">{{item.createTime}}</view>
				</view>
			</view>
			<view class="no_date" v-else>
				暂无记录
			</view>
		</scroll-view>
		<view>
			<u-modal :show="reasonFlag" title="拒绝原因" :content='reason' confirmText="关闭" confirmButtonShape="circle"
				@confirm="reasonFlag = false"></u-modal>
		</view>
		<view class="btn_container">
			<view class="btn" @click="back()">返回提现</view>
		</view>
	</view>
</template>

<script>
	import {
		GetAgentCashOutStopRecord
	} from "../../../api/withdraw.js"
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				tabList: [{
						label: "审核中",
						value: 0
					},
					{
						label: "已同意",
						value: 1
					},
					{
						label: "已拒绝",
						value: 2
					},
				],
				state: 0,
				payList: [],
				agentId: 0,
				pageParam: {
					pageIndex: 1,
					pageSize: 10
				},
				reasonFlag: false,
				reason: ""
			}
		},
		computed: {
			...mapState('user', ['userInfo'])
		},
		onShow() {
			this.payList = []
			this.getList()
		},
		methods: {
			//获取列表数据
			async getList() {
				let req = {
					agentId: this.userInfo.agentId,
					pageIndex: this.pageParam.pageIndex,
					pageSize: this.pageParam.pageSize,
					state: this.state,
				}
				const res = await GetAgentCashOutStopRecord(req)
				if (res) {
					this.payList = this.payList.concat(res.items)
				} else {
					this.payList = []
				}
			},

			// 切换状态
			tabClick(item) {
				this.state = item.value
				this.pageParam.pageIndex = 1
				this.payList = []
				this.getList()
			},

			//查看原因
			viewReason(val) {
				this.reason = val
				this.reasonFlag = true
			},

			// 审核状态
			stateText(val) {
				switch (val) {
					case 0:
						return "审核中";
					case 1:
						return "已同意";
					case 2:
						return "已拒绝";
					default:
						break;
				}
			},

			//返回提现
			back() {
				uni.navigateBack({
					delta: 1
				});
			},

			//加载更多
			loadMore() {
				this.pageParam.pageIndex++;
				this.getList()
			},
		}
	}
</script>

<style lang="scss" scoped>
	.warpper {
		width: 100%;
		height: 100vh;
		position: relative;
	}

	.pay_container {
		width: 100%;
		height: 90vh;
		padding-top: 110rpx;
		padding-bottom: 150rpx;
		box-sizing: border-box;
		overflow-y: scroll;

		.tab_container {
			width: 100%;
			height: 96rpx;
			line-height: 96rpx;
			display: flex;
			justify-content: space-around;
			align-items: center;
			white-space: nowrap;
			background-color: #fff;
			box-shadow: 0px 1px 2px 0px rgba(0, 0, 0, 0.25);
			position: fixed;
			top: 0;
			left: 0;
			right: 0;

			.tab_item {
				flex: 1;
				height: 80rpx;
				display: inline-block;
				text-align: center;
				margin: 0 20rpx;
			}

			/* 字体颜色 */
			.f-color {
				color: #636263;
			}

			/* 选中字体颜色 */
			.f-color-active {
				height: 80rpx;
				color: #3E56BA;
				border-bottom: 3px solid #3E56BA;
			}
		}

		.pay_item {
			width: 95%;
			padding: 20rpx 24rpx;
			box-sizing: border-box;
			border-bottom: 2px solid #D5D5D5;
			margin: 0 auto;

			.pay_content {
				width: 100%;
				height: 50%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				color: rgb(0, 0, 0);
				font-family: 思源黑体;
				font-size: 28rpx;
				font-weight: 400;

				.price {
					color: rgb(62, 86, 186);
				}
			}

			.pay_time {
				height: 50%;
				display: flex;
				align-items: center;
				color: rgb(183, 183, 183);
				font-family: 思源黑体;
				font-size: 22rpx;
				font-weight: 400;
			}
		}

		.no_date {
			width: 100%;
			height: 100%;
			display: flex;
			justify-content: center;
			align-items: center;
			font-weight: bold;
			color: #9B9B9B;
		}
	}

	.btn_container {
		position: absolute;
		left: 0;
		bottom: 0rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		padding: 0 22rpx;
		padding-bottom: 40rpx;
		box-sizing: border-box;
		background-color: #fff;
		z-index: 99;

		.btn {
			width: 100%;
			height: 80rpx;
			background-color: #3E56BA;
			border-radius: 16rpx;
			color: #fff;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>